package Ms

//
//import (
//	"database/sql"
//	"fmt"
//	"db2s/dataDispos"
//	"db2s/global"
//	"os"
//	"runtime"
//	"strconv"
//	"time"
//)
//
//type DBConnStruct struct {
//	DBDevice        string
//	JDBC            string
//	MaxIdleConns    int
//	MaxOpenConns    int
//	ConnMaxIdleTime time.Duration
//	ConnMaxLifetime time.Duration
//}
//
//// MaxConnectionSum 获取当前可用连接的最大连接数
//func (dbs *DBConnStruct) MaxConnectionSum(db *sql.DB) (int64, error) {
//	var (
//		event                  = "[MaxConnectionSum]"
//		tableData              map[string]interface{}
//		maxAvailableConnection int64
//		execTimeout            int64
//		err                    error
//	)
//	pc, _, _, _ := runtime.Caller(1)
//	callingFunc := runtime.FuncForPC(pc)
//	callFile, callLine := callingFunc.FileLine(pc)
//	callFunc := callingFunc.Name()
//	callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
//	vlog = fmt.Sprintf("(%d) %v %s Query the max available connection for statistical information", 1, callFuncInfo, event)
//	global.Wlog.Debug(vlog)
//	dispos := dataDispos.InstanceActiveS{DBType: DBType, DB: db}
//	strsql := fmt.Sprintf("select (select @@MAX_CONNECTIONS)-count(*) as 'maxAvailableConnection' from sys.dm_exec_connections")
//	var f1 any
//	if execTimeout, f1, err = dispos.SqlQuery(strsql, "map"); err != nil {
//		vlog = fmt.Sprintf("(%d) %v %v The execution of a sql statement failed. sql is {%v},error is {%v}", 1, callFuncInfo, event, strsql, err)
//		global.Wlog.Warn(vlog)
//		return 0, err
//	} else {
//		tableData = f1.(map[string]interface{})
//	}
//	if v, ok := tableData["maxAvailableConnection"]; ok {
//		if maxAvailableConnection, err = strconv.ParseInt(fmt.Sprintf("%v", v), 10, 64); err != nil {
//			vlog = fmt.Sprintf("(%d) %v %s max available connection  conversion failed . sql is %s, error is %s", 1, callFuncInfo, event, strsql, err)
//			global.Wlog.Warn(vlog)
//			maxAvailableConnection = 0
//			return maxAvailableConnection, nil
//		}
//	}
//	vlog = fmt.Sprintf("(%d) %v %v A sql statement was executed is successfully. sql is {%v}, exec timeout is {%vms}", 1, callFuncInfo, event, strsql, execTimeout)
//	global.Wlog.Debug(vlog)
//	vlog = fmt.Sprintf("(%d) %v %s The max available connection  query is successful. result is {%v}", 1, callFuncInfo, event, maxAvailableConnection)
//	global.Wlog.Debug(vlog)
//	return maxAvailableConnection, nil
//}
//
///*
//连接数据库，返回连接内存地址
//*/
//func (dbs *DBConnStruct) openDb() (map[string]*sql.DB, map[string]int64, error) {
//	var (
//		maxConnectionSum int64
//	)
//	db, err := sql.Open(dbs.DBDevice, dbs.JDBC)
//	if err != nil {
//		global.Wlog.Error("(0) database open fail. Error Info: ", err)
//		return nil, nil, err
//	}
//	if err = db.Ping(); err != nil {
//		global.Wlog.Error("(0) database connection fail. Error Info: ", err)
//		return nil, nil, err
//	}
//	db.SetMaxIdleConns(dbs.MaxIdleConns)
//	db.SetMaxOpenConns(dbs.MaxOpenConns)
//	if maxConnectionSum, err = dbs.MaxConnectionSum(db); err != nil {
//		return nil, nil, err
//	} else {
//		db.SetMaxOpenConns(int(maxConnectionSum / 2))
//	}
//	return map[string]*sql.DB{"single": db}, map[string]int64{"single": maxConnectionSum}, nil
//}
//
//// Close 参数复原
//func (dbs *DBConnStruct) Close(db map[string]*sql.DB) {
//
//}
//
//func (dbs *DBConnStruct) Open(_ bool) (map[string]*sql.DB, map[string]int64, error) {
//	defer func() {
//		if err1 := recover(); err1 != nil {
//			fmt.Println("oracle database create session connection fail, Check the database connection information.err info is ", err1)
//			os.Exit(0)
//		}
//	}()
//	return dbs.openDb()
//}
